package com.yuyou.train.user.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yuyou.train.service.api.user.entity.User;
import com.yuyou.train.service.api.user.service.UserAPI;
import com.yuyou.train.user.service.IUserDataConfigService;
import com.yuyou.train.user.service.IUserService;
import com.yuyou.train.user.vo.req.ReqUser;
import com.yuyou.train.util.bean.ResBoolSimpleInfo;
import com.yuyou.train.util.enums.user.UserEnums;
import com.yuyou.train.util.tool.DefindBeanUtils;





@RestController
public class UserAPIImpl implements UserAPI{

	@Autowired
	private IUserService userService;
	
	@Autowired
	private IUserDataConfigService userDataConfigService;
	
	@Override
	public int insert(@RequestBody User user) {
		return userService.insert(user);
	}

	@Override
	public int update(@RequestBody  User user) {
		return userService.updateByPrimaryKeySelective(user);
	}
	
	
	
	@Override
	public User selectByUserId(@RequestParam("userId") String userId) {
		User user=userService.selectByPrimaryKey(userId);
		return user;
	}

	@Override
	public List<User> findUsers(@RequestBody  User user) {
		ReqUser reqUser=new ReqUser();
		DefindBeanUtils.copyProperties(user, reqUser);
		List<User> list=userService.findUsers(reqUser);
		return list;
	}

	@Override
	public User selectUsersByPhone(@RequestParam("phone") String phone) {
		return userService.selectUsersByPhone(phone);
	}


	@Override
	public ResBoolSimpleInfo resetPass(@RequestParam("phone") String phone, @RequestParam("password") String password) {
		User user=this.selectUsersByPhone(phone);	
		User updateUser=new User();
		updateUser.setId(user.getId());
		updateUser.setPassword(password);
		//激活账号
		updateUser.setStatus(UserEnums.status.normal.getValue());
		userService.updateByPrimaryKeySelective(updateUser);		
		return ResBoolSimpleInfo.getSuccessInfo();
	}

	@Override
	public List<String> findUserDataConfig(@RequestParam("userId") String userId,@RequestParam("type") String type) {
		return userDataConfigService.findDataIdByUserIdAndType(userId, type);
	}


	

	
}
